<!DOCTYPE html>
<html class="x-admin-sm">

<head>
    <meta charset="UTF-8">
    <title>用户列表</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi"/>
    <link rel="stylesheet" href="../.././css/font.css">
    <link rel="stylesheet" href="../.././css/xadmin.css">
    <script src="../../layui/layui.js" charset="utf-8"></script>
    <script type="text/javascript" src="../../js/xadmin.js"></script>
    <!--[if lt IE 9]>
    <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
    <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>

<body>
<div class="x-nav">
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       onclick="location.reload()" title="刷新">
        <i class="layui-icon layui-icon-refresh" style="line-height:30px"></i>
    </a>
</div>
<div class="layui-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body ">
                    <table id="config-list-table" class="layui-table" lay-filter="config-list"></table>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script>
    layui.use(['table'],
    function () {
        var table = layui.table;
        /**
         * 监听表格渲染
         */
        table.render({
             elem: '#config-list-table'
            ,height: 600
            ,url: '/api/config/configList' //数据接口
            ,page: true //开启分页
            ,cols: [[ //表头
                {field: 'id', title: 'ID',sort: true, fixed: 'left'}
                ,{field: 'configName', title: '名称'}
                ,{field: 'configValue', title: '属性值', edit: 'configValue',sort:true}
            ]]
        });

        table.on('edit(config-list)', function(obj){ //注：edit是固定事件名，test是table原始容器的属性 lay-filter="对应的值"
            console.log(obj.value); //得到修改后的值
            console.log(obj.field); //当前编辑的字段名
            console.log(obj.data); //所在行的所有相关数据
            if(obj.field === 'configValue'){
                console.log("编辑系统配置")
            }
            $.ajax({
                url:"/api/config/updateConfigValue",
                method:'post',
                data:{
                    key:obj.data.configKey,
                    value:obj.value
                },
                success:function (data) {
                    if(data.code === "200"){
                        layer.msg("修改成功")
                    }
                }
            })
        });
    });
</script>
</html>